package com.xtpt.disaster.common.File;

import com.xtpt.disaster.bean.NodeInfo;
import com.xtpt.disaster.common.AgentInfo;
import com.xtpt.disaster.common.PropertyConfig;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author jack_xin
 * @ClassName clientAgentUrlGenerator
 * @Desc 生成java代理端的post请求有路径，用于客户端执行相关命令。
 * @date 2021年12月24日 10:53
 * @Version TODO
 */
@Component
public class ClientAgentUrlGenerator {
    @Autowired
    AgentInfo agentInfo;

    @Autowired
    PropertyConfig config;

    public String generateUrl(NodeInfo nodeInfo){
        String nodeIp = nodeInfo.getNodeIp();
        String agentUrl = nodeIp + ":" + agentInfo.getClientPort() + agentInfo.getClientPath();
        return agentUrl;
    }

    public String generateServerAgentUrl() {
        String serverIp = config.getServerIp();
        String agentUrl = serverIp + ":" + agentInfo.getClientPort() + agentInfo.getClientPath();
        return agentUrl;
    }
}
